﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF_Encrypt_Demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            const int numberOfLists = 10; // 列表数量
            const int pointsPerList = 500; // 每个列表中的点数量
            List<List<PointData>> allPoints = new List<List<PointData>>(numberOfLists);

            // 初始化多个 List
            Random random = new Random();
            for (int j = 0; j < numberOfLists; j++)
            {
                List<PointData> points = new List<PointData>(pointsPerList);
                for (int i = 0; i < pointsPerList; i++)
                {
                    double x = Math.Round(random.NextDouble() * 100, 6);
                    double y = Math.Round(random.NextDouble() * 100, 6);
                    double speed = Math.Round(random.NextDouble() * 50, 6);
                    points.Add(new PointData(x, y, speed));
                }
                allPoints.Add(points);
            }

            string baseDirectory = @"D:\File\Desktop\test"; // 基础目录
            string measurementType = "speed"; // 可以根据实际需要修改测量类型
            string filePath = DataFileHelper.GetFilePath(baseDirectory, measurementType); // 获取文件路径

            Stopwatch stopwatch = new Stopwatch(); // 创建一个计时器

            stopwatch.Start(); // 开始计时
            DataFileHelper.SavePointsToFile(filePath, allPoints);
            stopwatch.Stop(); // 停止计时

            Console.WriteLine($"所有数据已加密并保存到文件：{filePath}");
            long elapsedMilliseconds1 = stopwatch.ElapsedMilliseconds;
            

            // 从文件读取并解密数据并计时
            stopwatch.Restart(); // 重启计时器
            List<List<PointData>> readPoints = DataFileHelper.ReadPointsFromFile(filePath);
            stopwatch.Stop(); // 停止计时
            long elapsedMilliseconds2 = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("数据已从文件中读取并解密。");
            


            // 打印读取的数据点
            stopwatch.Restart(); // 重启计时器
            for (int listIndex = 0; listIndex < readPoints.Count; listIndex++)
            {
                Console.WriteLine($"\n--- List {listIndex + 1} ---");
                foreach (var point in readPoints[listIndex])
                {
                    Console.WriteLine($"X: {point.X}, Y: {point.Y}, Speed: {point.Speed}");
                }
                Console.WriteLine("======"); // 打印分隔线
            }
            stopwatch.Stop(); // 停止计时
            long elapsedMilliseconds3 = stopwatch.ElapsedMilliseconds;
            Console.WriteLine($"保存数据所用时间：{elapsedMilliseconds1} 毫秒");
            Console.WriteLine($"读取数据所用时间：{elapsedMilliseconds2} 毫秒");
            Console.WriteLine($"打印数据所用时间：{elapsedMilliseconds3} 毫秒");
            Console.WriteLine("Press Any Key To Exit..");
            Console.ReadLine();
        }
    }
}
